package com.mapper;


import com.bean.User;
import org.mybatis.spring.SqlSessionTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserMapperimpl implements UserMapper {
    private SqlSessionTemplate sqlSession;

    public void setSqlSession(SqlSessionTemplate sqlSession) {
        this.sqlSession = sqlSession;
    }
//删除方法报错 导致之前的方法也不会执行 (事务)
    @Override
    public List<User> selectUser() {
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> users = mapper.selectUser();
//        User user = new User(4,"王","123",1);
        Map map =new HashMap();
        map.put("iduser",4);
        map.put("name","王");
        map.put("password","123");
        map.put("score",1);
        add(map);
        delete(5);
      return users;
    }

    @Override
    public int add(Map map) {
        return sqlSession.getMapper(UserMapper.class).add(map);
    }

    @Override
    public int delete(int iduser) {
        return sqlSession.getMapper(UserMapper.class).delete(iduser);
    }
}
